import EventCenter from "../../TFrame/script/helper/EventCenter";
import EventNames from "../EventNames";

const {ccclass, property, requireComponent} = cc._decorator;

const scaleMax = 1.8;

@ccclass
@requireComponent(cc.Sprite)
export default class ScaleButton extends cc.Component {

    @property({type:cc.SpriteFrame, displayName:"+号"})
    bigSpriteFrame: cc.SpriteFrame = null;

    @property({type:cc.SpriteFrame, displayName:"-号"})
    smallSpriteFrame: cc.SpriteFrame = null;

    @property(cc.Label)
    scaleLabel:cc.Label = null;

    thisSprite: cc.Sprite = null;

    isBigState = true;

    protected onLoad(): void {
        this.thisSprite = this.node.getComponent(cc.Sprite);
        // this.scaleLabel.string = this.isBigState? (scaleMax * 100) + "/%" : "100%"

        EventCenter.once(EventNames.DiffShowDone, ()=>{
            this.node.on(cc.Node.EventType.TOUCH_END, this.clicked, this);
        }, this);

        EventCenter.once(EventNames.TutorialDone, ()=>{
            this.node.on(cc.Node.EventType.TOUCH_END, this.clicked, this);
        }, this)

        EventCenter.once(EventNames.DiffAllFound, () => { 
            this.node.active = false;
        }, this);

        EventCenter.on(EventNames.ReqShowHint, ()=>{
            console.log(`ScaleButton isBigState:${this.isBigState}`)
            if(this.isBigState == false) {
                this.clicked();
            }
        }, this);
    }

    clicked() {
        EventCenter.emit(EventNames.ScaleChange, this.isBigState? scaleMax: 1.0);
        this.scaleLabel.string = this.isBigState? (scaleMax * 100) + "%" : "100%"
        this.isBigState = !this.isBigState;
        this.thisSprite.spriteFrame = this.isBigState? this.bigSpriteFrame: this.smallSpriteFrame;
    }

}
